﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication.Models;
using System.Text;

namespace WebApplication.WebPage
{
    public partial class Index : System.Web.UI.Page
    {
        private readonly string Token = "zhengshuai";
        protected void Page_Load(object sender, EventArgs e)
        {
            Auth();
        }

        private void Auth()
        {
            string signature = Request["signature"];
            string timespan = Request["timestamp"];
            string nonce = Request["nonce"];
            string echostr = Request["echostr"];
            if (Request.HttpMethod == "GET")
            {
                if (CheckSignature.Check(signature, timespan, nonce, Token))
                {
                    WriteContent(echostr);
                }
                else
                {
                    WriteContent("signature:" + signature);
                    WriteContent("timespan:" + timespan);
                    WriteContent("nonce:" + nonce);
                    WriteContent("echostr:" + echostr);
                    WriteContent("failed:" + signature + "," + CheckSignature.GetSignature(timespan, nonce, Token) + "。" + "如果你在浏览器中看到这句话，说明此地址可以被作为微信公众号后台的URL，请注意保持Token一致");
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        private void WriteContent(string str)
        {
            Response.Output.Write(str);
        }
    }
}